﻿using System;
using System.Linq;
using Orange.Logistics.Models;
using Orange.Logistics.Infrastructure;
using Orange.Logistics.Services;
using System.Web.Mvc;
using Newtonsoft.Json;
using System.Collections.Generic;

namespace Orange.Logistics.Controllers {

    public class StockDetailController : BaseController<StockDetail> {

        private readonly IStockDetailService service;

        public StockDetailController(IStockDetailService service)
            : base(service) {
            this.service = service;
        }

        public override JsonResult GetGrid() {
            InitPager();
            int total;
            var list = service.GetDetailList(PG.pageNo, PG.pageSize, PG.where, PG.sort, PG.asc, out total);
            return Json(new { Rows = list, Total = total });
        }

        protected override Func<StockDetail, object> GetOrderBy(string sort) {
            return sd => {
                switch (sort) {
                    case "Did":
                        return sd.Did;
                    case "Buttressno":
                        return sd.Buttressno;
                    case "Detailseqno":
                        return sd.Detailseqno;
                    case "Memorycard":
                        return sd.Memorycard;
                    case "Memoryid":
                        return sd.Memoryid;
                    case "Floors":
                        return sd.Floors;
                    case "Unit":
                        return sd.Unit;
                    case "Hottoys":
                        return sd.Hottoys;
                    case "Status":
                        return sd.Status;
                    default:
                        return sd.Did;
                }
            };
        }

        protected override void Dispose(bool disposing) {
            if (disposing) {
                service.Dispose();
            }
        }
    }
}